home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / gcc / ixemlsrc.lha / ixemul / utils / ixrun.c < prev    next >
C/C++ Source or Header  |  1996-03-13  |  2KB  |  75 lines

  1. #include <stdlib.h>
  2. #include <string.h>
  3. #include <stdio.h>
  4.  
  5. char VERSION[] = "\000$VER: ixrun 1.0 (10.11.95)";
  6.  
  7. static void usage(void)
  8. {
  9.   fprintf(stderr, "Usage: ixrun [-n | -q] filename [arguments...]
  10. -n\tdon't add quotes (\") around the arguments
  11. -q\tadd quotes (\") around the arguments (default)
  12. -nv\tas -n, but print the command line to standard error, don't execute it
  13. -qv\tas -q, but print the command line to standard error, don't execute it\n");
  14.   exit(1);
  15. }
  16.  
  17. main(int argc, char **argv)
  18. {
  19.   char *p;
  20.   long size, i, first_opt = 1, add_quotes = 2, debug = 0;
  21.  
  22.   if (argc == 1)
  23.     usage();
  24.   if (!strcmp(argv[1], "-q") || !strcmp(argv[1], "-qv"))
  25.   {
  26.     if (argc == 2)
  27.       usage();
  28.     first_opt++;
  29.     debug = !strcmp(argv[1], "-qv");
  30.   }
  31.   if (!strcmp(argv[1], "-n") || !strcmp(argv[1], "-nv"))
  32.   {
  33.     if (argc == 2)
  34.       usage();
  35.     add_quotes = 0;
  36.     first_opt++;
  37.     debug = !strcmp(argv[1], "-nv");
  38.   }
  39.   if (argv[first_opt][0] == '/' && (p = strchr(argv[first_opt] + 1, '/')))
  40.   {
  41.     *p = ':';
  42.     (argv[first_opt])++;
  43.   }
  44.   for (size = strlen(argv[first_opt]) + 1, i = first_opt + 1; argv[i]; i++)
  45.     size += strlen(argv[i]) + 1 + add_quotes;
  46.   p = malloc(size);
  47.   if (p == NULL)
  48.   {
  49.     fprintf(stderr, "couldn't allocate %d bytes\n", size);
  50.     exit(1);
  51.   }
  52.   strcpy(p, argv[first_opt]);
  53.   for (i = first_opt + 1; argv[i]; i++)
  54.   {
  55.     if (add_quotes)
  56.       strcat(p, " \"");
  57.     else
  58.       strcat(p, " ");
  59.     strcat(p, argv[i]);
  60.     if (add_quotes)
  61.       strcat(p, "\"");
  62.   }
  63.   if (debug)
  64.     fprintf(stderr, "command line = '%s'\n", p);
  65.   else
  66.   {
  67.     int result, omask;
  68.  
  69.     omask = sigsetmask(~0);
  70.     result = !Execute(p, NULL, NULL);
  71.     sigsetmask(omask);
  72.     exit(result);
  73.   }
  74. }
  75.